s = input().split()
p = int(s[0])
q = int(s[1])
d = int(s[2])
c = int(s[3])
n = (p)*(q)
#print(n)
print(pow(c,d,n))